﻿using UnityEngine;
using System.Collections;

public class EnemySpawn : MonoBehaviour {


		// enemy spawn timers
		public GameObject enemy; // creating an enemy
		public static float defaultEnemySpawnt = 5f;
		public static float enemySpawnt = 5f; // ajastin
	
	// Update is called once per frame
	void Update () {

		enemySpawnt -= Time.deltaTime; // aika kuluu
		
		
		// speissistä ampuu
		if (enemySpawnt <= 0f) {


			// teleporttaillaan satunnaiseen paikkaan
			Vector3 newpos = transform.position;
			newpos.x = Random.Range (-50,50);
			newpos.y = Random.Range (-50,50);

			//transform.position = newpos;
			
			enemySpawnt = defaultEnemySpawnt; //nollataan aikalaskuri
			
			GameObject clone;
			
			// luodaan klooni
			clone = Instantiate (enemy,
			                     transform.position+newpos,
			                     transform.rotation) as GameObject;
		}
	
	}
}
